package tools;

import java.sql.*;
import oracle.jdbc.pool.OracleDataSource;

public class Proses {

    Connection conn;

    /*
     * method dibawah digunakan untuk mengeset database.
     */
    public void getDBConnection() throws SQLException {
        OracleDataSource ds;
        ds = new OracleDataSource();
//        ds.setURL("jdbc:oracle:thin:@localhost:1521:XE");
//        conn = ds.getConnection("system", "hr");
        ds.setURL("jdbc:Oracle:thin:@172.23.9.185:1521:orcl");
        conn = ds.getConnection("MHS105314089", "MHS105314089");
    }

    /*
     * method dibawah digunakan untuk mengambil status dari data base berdasarkan username tertentu.
     */
    public String isintablestaff(String staffid) throws SQLException {
        String query = "select STATUS from PENGGUNA where USERNAME='" + staffid + "'";
        String hasil = null;
        getDBConnection();
        java.sql.Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
        ResultSet rz;
        rz = stmt.executeQuery(query);
        while (rz.next()) {
            hasil = (rz.getString(1));
        }
        return hasil;
    }

    /*
     *method dibawah digunakan untuk mengambil password dari data base berdasarkan username tertentu.
     */
    public String isintablestaff1(String staffid) throws SQLException {
        String query = "select PASSWORD from PENGGUNA where USERNAME='" + staffid + "'";
        String hasil = null;
        getDBConnection();
        java.sql.Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
        ResultSet rz;
        rz = stmt.executeQuery(query);
        while (rz.next()) {
            hasil = (rz.getString(1));
        }
        return hasil;
    }

    /*
     * method dibawah digunakan untuk mengambil username dari data base berdasarkan username tertentu.
     */
    public String isintablestaff2(String staffid) throws SQLException {
        String query = "select USERNAME from PENGGUNA where USERNAME='" + staffid + "'";
        String hasil = null;
        getDBConnection();
        java.sql.Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
        ResultSet rz;
        rz = stmt.executeQuery(query);
        while (rz.next()) {
            hasil = (rz.getString(1));
        }
        return hasil;
    }  
}
